package com.zzty.txj1.controller;

import com.zzty.txj1.entity.User;
import com.zzty.txj1.service.UserService;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
@RequestMapping("/changeInformation")
public class ChangeInformationController {
    @Autowired
    UserService userService;
    @RequestMapping(value = "/updateUser")
    public Integer updateUser(User user){
        Integer result=userService.updateUser(user);
        return result;
    }
    @RequestMapping(value = "/getAllUsers",method = RequestMethod.POST)
    public List<User> getAllUsers(){
        List<User> users=userService.getAllUsers();
        return users;
    }
    @RequestMapping(value = "/encrypt")
    public String encrypt(User user){
        String newPassword = new SimpleHash("md5",
                user.getPassword(), ByteSource.Util.bytes(user.getName()), 2).toHex();
        return newPassword;
    }
}
